#include "StdAfx.h"
#include "statestack.h"
#include "statemain.h"
#include "stateoption.h"
#include "statecredit.h"
#include "StateMainMenu.h"

StateMainMenu::StateMainMenu ()
{
}

StateMainMenu::~StateMainMenu ()
{
}

void StateMainMenu::OnEnter ()
{
	m_background.Init("../Resources/Textures/MainMenuBg.tga");
	m_button1.Init("../Resources/Textures/Playbtn.tga", 150.0f/800.0f, 420.0f/600.0f, 500.0f/800.0f, 80.0f/600.0f);
	m_button2.Init("../Resources/Textures/Shopbtn.tga", 150.0f/800.0f, 320.0f/600.0f, 500.0f/800.0f, 80.0f/600.0f);
	m_button3.Init("../Resources/Textures/Optionbtn.tga", 150.0f/800.0f, 220.0f/600.0f, 500.0f/800.0f, 80.0f/600.0f);
	m_button4.Init("../Resources/Textures/Creditbtn.tga", 150.0f/800.0f, 120.0f/600.0f, 500.0f/800.0f, 80.0f/600.0f);

	m_button1.SetOnClickListener( &StateMainMenu::OnPlayBtnPressed );
	m_button2.SetOnClickListener( &StateMainMenu::OnShopBtnPressed );
	m_button3.SetOnClickListener( &StateMainMenu::OnOptionBtnPressed );
	m_button4.SetOnClickListener( &StateMainMenu::OnCreditBtnPressed );
}

bool StateMainMenu::OnKeyDown (int keycode)
{
	return false;
}

bool StateMainMenu::OnKeyUp (int keycode)
{
	return false;
}

bool StateMainMenu::OnTouchDown (float xPos, float yPos)
{
	if ( !m_button1.OnTouchDown(xPos, yPos) )
		if ( !m_button2.OnTouchDown(xPos, yPos) )
			if ( !m_button3.OnTouchDown(xPos, yPos) )
				if ( !m_button4.OnTouchDown(xPos, yPos) )
					return false;
	return true;
}

bool StateMainMenu::OnTouchUp (float xPos, float yPos)
{
	m_button1.OnTouchUp(xPos, yPos);
	m_button2.OnTouchUp(xPos, yPos);
	m_button3.OnTouchUp(xPos, yPos);
	m_button4.OnTouchUp(xPos, yPos);
	return false;
}

void StateMainMenu::Render ()
{
	m_background.Render();
	m_button1.Render();
	m_button2.Render();
	m_button3.Render();
	m_button4.Render();
}

void StateMainMenu::Update(float deltaTime)
{
	m_background.Update(deltaTime);
	m_button1.Update(deltaTime);
	m_button2.Update(deltaTime);
	m_button3.Update(deltaTime);
	m_button4.Update(deltaTime);
}

void StateMainMenu::OnPlayBtnPressed ()
{
	StateMain* state = new StateMain(15, 20); 
	GetStateStack()->SetState (state);
}

void StateMainMenu::OnShopBtnPressed ()
{
}

void StateMainMenu::OnOptionBtnPressed ()
{
	/*StateOption* state = new StateOption();
	GetStateStack()->SetState (state);*/
}

void StateMainMenu::OnCreditBtnPressed ()
{/*
	StateCredit* state = new StateCredit();
	GetStateStack()->SetState (state);*/
}
